package com.example.changtest.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.viewpager.widget.PagerAdapter
import com.example.changtest.R
import com.example.changtest.ui.D3Activity
import com.example.changtest.ui.view.BliConstraintLayout

class BliPageAdapter(var d3Activity: D3Activity,val mFragments: MutableList<Int>) : PagerAdapter() {
    override fun getCount(): Int {
      return  mFragments.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
          return view ==  `object`
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        //return super.instantiateItem(container, position)
        val view = LayoutInflater.from(d3Activity).inflate(R.layout.vp_item,null)  as ViewGroup
        var img = view.findViewById<ImageView>(R.id.img)
        //var img = ImageView(d3Activity)
        img.setImageResource(mFragments[position])
        container.addView(view)
        //最后要返回的是控件本身
        return view

    }
    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        //super.destroyItem(container, position, `object`)
        container.removeView(`object` as View)
    }

//    override fun getPageTitle(position: Int): CharSequence? {
//        return super.getPageTitle(position)
//    }
}
